import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import React, { useImperativeHandle, useState } from "react";
import { Collapse, Modal } from "antd";
import "./_style.less";
import _ from "lodash";
import { renderTable } from "./verifyCommon";
const { Panel } = Collapse;
const ValidModal = React.forwardRef((props, ref) => {
    const { dataList, content, isMaskClose = false, width = 200 } = props;
    const [isOpen, setIsOpen] = useState(false);
    const [activeKeyArr, setActiveKeyArr] = useState([]);
    useImperativeHandle(ref, () => ({
        show: async (params) => {
            setIsOpen(true);
        },
        close: () => {
            setIsOpen(false);
        },
    }));
    const changeActiveKey = (id) => {
        setActiveKeyArr(id);
    };
    const renderList = () => {
        if (!dataList || !dataList.length) {
            return;
        }
        const cloneData = _.cloneDeep(dataList);
        const selectedItems = [];
        // const menus = showDetailButtonMenus ? showDetailButtonMenus() : [];
        let groupDataByType = [];
        groupDataByType = cloneData.map((item) => {
            item.verifyResult = _.groupBy(item.verifyResult, "type");
            return item;
        });
        return groupDataByType.length > 0 ? (_jsx(Collapse, { activeKey: activeKeyArr, onChange: changeActiveKey, children: groupDataByType.map((item) => {
                const verifyResult = item.verifyResult;
                let mainLen = 0;
                //@临时方案，总数需要减去母公式的数据
                if (verifyResult) {
                    Object.keys(verifyResult).map((key, index) => {
                        const mainVerifyResult = item.verifyResult[key]
                            ? item.verifyResult[key].filter((r) => r.dynamicType && r.dynamicType === "MAIN")
                            : null;
                        if (mainVerifyResult && mainVerifyResult.length) {
                            mainLen = mainLen + mainVerifyResult.length;
                        }
                    });
                }
                /*兼容处理公式没有匹配上的情况 begin*/
                const verifyKeys = Object.keys(item.verifyResult);
                if (selectedItems && selectedItems.length && verifyKeys) {
                    for (let i = 0; i < selectedItems.length; i++) {
                        if (!verifyKeys.includes(selectedItems[i])) {
                            return;
                        }
                    }
                }
                /*兼容处理公式没有匹配上的情况 end*/
                const total = mainLen
                    ? parseInt(item.statisticsItem.total) - mainLen
                    : item.statisticsItem.total;
                const vefiryResult = item.verifyResult;
                return (_jsx(Panel, { header: `${item.title}   共${total}条，校验不通过${item.statisticsItem.fail}条`, children: item.verifyResult ? (_jsx(_Fragment, { children: renderTable(vefiryResult, []) })) : (_jsx("div", { className: "no-rules", children: "\u6682\u672A\u8BBE\u7F6E\u52FE\u7A3D\u6821\u9A8C" })) }, item.id || item.fid));
            }) })) : (_jsx("div", { className: "no-data", children: "\u6682\u65E0\u6570\u636E" }));
    };
    return (_jsx(Modal, { open: isOpen, centered: true, maskClosable: isMaskClose, title: "查看无效公式", footer: null, width: width, onCancel: () => setIsOpen(false), children: _jsx("div", { className: "valid-modal-body", children: renderList() }) }));
});
export default ValidModal;
